import sys
import argparse
import logging

import scheduler

__author__ = 'Robert Smallshire'

logger = logging.getLogger('twiterator.main')

def configure_logging(log_level):
    numeric_level = getattr(logging, log_level.upper(), None)
    if not isinstance(numeric_level, int):
        raise ValueError('Invalid log level: %s' % loglevel)
    logging.basicConfig(level=numeric_level)


def main(argv=None):
    if argv is None:
        argv = sys.argv[1:]

    parser = argparse.ArgumentParser(description='Send pre-prepared tweets')
    parser.add_argument('tweetfile', help='The path to a file containing one tweet per line')
    parser.add_argument('-y', '--yes', action='store_true', dest='for_real', default=False, help="Actually send the tweet!")
    parser.add_argument('-l', '--log-level', dest='log_level', default='warning', choices=['debug', 'info', 'warning', 'error', 'critical'], help='The log level')

    args = parser.parse_args(argv)
    configure_logging(args.log_level)
    logger.debug(args)
    
    scheduler.interactive(args.tweetfile, None, args.for_real)

if __name__ == '__main__':
    sys.exit(main())